using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MicroMsg.Storage
{
	public class SnsMsgStorage : StorageTable<SnsMsg, int>
	{
		public SnsMsgStorage() : base((SnsMsg sm) => sm.nMsgID)
		{
		}
		public List<SnsMsg> getListOrderByTime(int startIndex, int int_0)
		{
			if (startIndex >= 0 && int_0 > 0 && base.isReady())
			{
				List<SnsMsg> result;
				try
				{
					result = Enumerable.ToList<SnsMsg>(Queryable.Take<SnsMsg>(Queryable.Skip<SnsMsg>(Queryable.OrderByDescending<SnsMsg, uint>(this.tableR, (SnsMsg msg) => msg.nCreateTime), startIndex), int_0));
				}
				catch (Exception ex)
				{
					Log.smethod_1("storage", "getListByTime  exception" + ex);
					result = null;
				}
				return result;
			}
			return null;
		}
		public List<SnsMsg> getListByUserName(string strUserName, string strObjectID, int start = 0, int int_0 = 2147483647)
		{
			if (!string.IsNullOrEmpty(strUserName) && !string.IsNullOrEmpty(strObjectID) && start >= 0 && int_0 > 0 && base.isReady())
			{
				List<SnsMsg> result;
				try
				{
					result = Enumerable.ToList<SnsMsg>(Queryable.Take<SnsMsg>(Queryable.Skip<SnsMsg>(Queryable.OrderByDescending<SnsMsg, uint>(Queryable.Where<SnsMsg>(this.tableR, (SnsMsg msg) => msg.strFromUsername == strUserName && msg.strObjectID == strObjectID), (SnsMsg msg) => msg.nCreateTime), start), int_0));
				}
				catch (Exception ex)
				{
					Log.smethod_1("storage", "getListByUserName  exception" + ex);
					result = null;
				}
				return result;
			}
			return null;
		}
		public SnsMsg getLast()
		{
			int num = base.count();
			if (num <= 0)
			{
				return null;
			}
			List<SnsMsg> list = base.getList(num - 1, 1);
			if (list != null && list.get_Count() > 0)
			{
				return Enumerable.First<SnsMsg>(list);
			}
			return null;
		}
		public bool deleteMsg(string strObjectID)
		{
			return base.method_6((SnsMsg msg) => msg.strObjectID == strObjectID);
		}
		public override void notify(int operation, SnsMsg item)
		{
			EventCenter.postCombineEvent(EventConst.ON_STORAGE_SNSMSG_ADD + operation, item);
		}
		public void test()
		{
			base.clearAll();
			DebugEx.getTimeSpan();
			for (int i = 0; i < 300; i++)
			{
				base.method_3(new SnsMsg());
			}
			base.clearAll();
			DebugEx.debugBreak();
		}
	}
}
